
#include "coin.h"


//coin::coin(QWidget *parent)
//    : QWidget{parent}
//{
//
//}
coin::coin(QString btnimg){
    QPixmap pix;
   pix.load(btnimg);
    this->setFixedSize(pix.width(),pix.height());
   this->setStyleSheet("QPushButton{border:0px;}");
   this->setGeometry(0,0,pix.width(),pix.height());
    this->setIcon(pix);
   this->setIconSize(QSize(pix.width(),pix.height()));
   timer1 = new QTimer(this);
   timer2 = new QTimer(this);
   //金币变银币
   connect(timer1,&QTimer::timeout,[=](){
       QPixmap pix;
       QString str=QString(":/po/res/Coin000%1").arg(this->min++);
       pix.load(str);
       this->setFixedSize(pix.width(),pix.height());
       this->setStyleSheet("QPushButton{border:0px;}");
       this->setIcon(pix);
       this->setIconSize(QSize(pix.width(),pix.height()));
       if(this->min>this->max){
           this->min=1;
           timer1->stop();
       }
   });
   //银币变金币
   connect(timer2,&QTimer::timeout,[=](){
       QPixmap pix;
       QString str=QString(":/po/res/Coin000%1").arg(this->max--);
       pix.load(str);
       this->setFixedSize(pix.width(),pix.height());
       this->setStyleSheet("QPushButton{border:0px;}");
       this->setIcon(pix);
       this->setIconSize(QSize(pix.width(),pix.height()));
       if(this->max < this->min){
           this->max=8;
           timer2->stop();
       }
   });
}



void coin::changeflag(){
   if(this->flag){
        timer1->start(30);
       this->flag=false;
   }
   else{
       timer2->start(30);
       this->flag=true;
   }

}
